'''
Created on 2017-6-21

@author: 24253
'''
from zs.content.baseurlcontent import BaseUrlContent
from zs.zsqueue import zspathqueue
from bs4 import BeautifulSoup as BS

from zs.zsqueue import zscontentqueue
from queue import Empty
import logging,requests,json

class XiaomiPath(BaseUrlContent):
    
    name = "xiaomi"
    
    def __init__(self):
        logging.debug("[path]["+self.name+"]:start!")
    
    def run(self):
        while True:
            try:
                url = zspathqueue.get(self.name)

                self.dojob(url)
            except Exception as ex:
                logging.error("[path]["+self.name+"]:"+str(url)+"解析失败")
                logging.error(ex)
        
    def dojob(self,url_b):
        response = requests.get(url_b)   #调用requests向服务器发送get请求
        res=response.content.decode()

        data_dict=json.loads(res)
# # print(data_dict)
 
        item_list = data_dict['mods']['itemlist']['data']['auctions']
#     print(item_list)
        
        for item in item_list:
    
            a_=item["detail_url"]

            
            zscontentqueue.put(self.name,"https:"+a_)#保存详细页面地址
    

